package com.keldian.mobilesafe.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.keldian.mobilesafe.R;
import com.keldian.mobilesafe.ui.SettingItemView;
import com.keldian.mobilesafe.utils.SharePrefenceTool;

public class Setup2Activity extends BaseSetupActivity {

    private SettingItemView siv_setup2_sim;
    /**
     * 读取手机sim的信息
     */
    private TelephonyManager tm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup2);
        siv_setup2_sim = (SettingItemView) findViewById(R.id.siv_setup2_sim);
        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        String sim = SharePrefenceTool.getSim(this);
        if (TextUtils.isEmpty(sim)) {
            //没有绑定
            siv_setup2_sim.setChecked(false);
        } else {
            //已经绑定
            siv_setup2_sim.setChecked(true);
        }

        siv_setup2_sim.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (siv_setup2_sim.isChecked()) {
                    siv_setup2_sim.setChecked(false);
                    //保存sim卡的序列号
                    SharePrefenceTool.setSim(Setup2Activity.this, null);
                } else {
                    siv_setup2_sim.setChecked(true);
                    //保存sim卡的序列号
                    String sim = tm.getSimSerialNumber();
                    SharePrefenceTool.setSim(Setup2Activity.this, sim);

                }

            }
        });


    }


    @Override
    public void showNext() {
        //取出是否绑定sim
        String sim = SharePrefenceTool.getSim(this);
        if (TextUtils.isEmpty(sim)) {
            //没有绑定
            Toast.makeText(this, "sim卡没有绑定", Toast.LENGTH_SHORT).show();
            return;
        }


        Intent intent = new Intent(this, Setup3Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.tran_in, R.anim.tran_out);

    }

    @Override
    public void showPre() {
        Intent intent = new Intent(this, Setup1Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.tran_pre_in, R.anim.tran_pre_out);


    }

}
